<?php
namespace app\common;
use app\BaseController;
use app\common\model\FirmModel;
use think\facade\Request;
use GuzzleHttp\Client;

class OpenApi extends BaseController{
    protected $api = 'https://mp.xhm.net.cn';
    protected $key = '';
    private $Client;
    public function __construct($firm_id) {
        $this->Client = new Client();
        $this->key = FirmModel::where('firm_id',$firm_id)->value('secret_key');
    }
    public function getKey($data){
        $res = $this->Client->post($this->api.'/auth/getKey',['form_params'=>$data])->getBody()->getContents();
        return json_decode($res,true);
    }
    // 请求接口 有参数
    public function openApiPost($url,$data=[]){
        $res = $this->Client->post($this->api.'/'.$url.'/'.$this->key,['form_params'=>$data])->getBody()->getContents();
        return json_decode($res,true);
    }
    
    public function openApiPostImage($url,$data=[]){
        return $this->Client->post($this->api.'/'.$url.'/'.$this->key,['form_params'=>$data])->getBody();
        // return json_decode($res,true);
    }
    // //获取业务验证文件
    // public function getWebWiewDomainConfirmfile(){
    //     $res = $this->Client->post($this->api.'/miniapp/getWebWiewDomainConfirmfile/'.$this->key)->getBody()->getContents();
    //     return json_decode($res,true);
    // }
    // //添加/删除业务域名
    // public function setWebViewDomain($data){
    //     $res = $this->Client->post($this->api.'/miniapp/setWebViewDomain/'.$this->key,['form_params'=>$data])->getBody()->getContents();
    //     return json_decode($res,true);
    // }
    // // 添加类目
    // public function addcategory($data){
    //     $res = $this->Client->post($this->api.'/miniapp/addcategory/'.$this->key,['form_params'=>$data])->getBody()->getContents();
    //     return json_decode($res,true);
    // }
    // //删除类目
    // public function deletecategory($data){
    //     $res = $this->Client->post($this->api.'/miniapp/deletecategory/'.$this->key,['form_params'=>$data])->getBody()->getContents();
    //     return json_decode($res,true);
    // }
}